$(function(){
	$('#tt').datagrid({
		url:'/taskReturn/listJson'
	});
	
});

function doSearch(){
	var taskType=$('#taskType').combobox('getValue');
	var mark=$('#markId').val();
	var startTime = $('#startTime').datebox('getValue');
	var endTime = $('#endTime').datebox('getValue');
	
	if (startTime != "" && endTime != "") {
		var diff = GetDateDiff(startTime, endTime, "second");
		if (diff > 0) {
			alert("开始时间不能小于结束时间！");
			return false;
		}
	}
	
	$('#tt').datagrid({
		url:'/taskReturn/listJson',
		queryParams:{
			taskType:taskType,
			mark:mark,
			startTime:startTime,
			endTime:endTime
		}
	});
	$('#tt').datagrid('unselectAll');
}

function GetDateDiff(startTime, endTime, diffType) {
    //将计算间隔类性字符转换为小写
    diffType = diffType.toLowerCase();
    var sTime = new Date(startTime);      //开始时间
    var eTime = new Date(endTime);  //结束时间
    
    var divNum = 1;
    switch (diffType) {
        case "second":
            divNum = 1000;
            break;
        case "minute":
            divNum = 1000 * 60;
            break;
        case "hour":
            divNum = 1000 * 3600;
            break;
        case "day":
            divNum = 1000 * 3600 * 24;
            break;
        default:
            break;
    }
    return parseInt((sTime.getTime() - eTime.getTime()) / parseInt(divNum));
}

